/**
 * Copyright 2017 The Jaeger Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package io.jaegertracing.spark.dependencies.elastic;

import org.apache.commons.lang3.time.DateUtils;
import org.elasticsearch.hadoop.cfg.HadoopSettings;
import org.elasticsearch.hadoop.cfg.Settings;
import org.elasticsearch.hadoop.rest.RestClient;
import org.apache.hadoop.conf.Configuration;
import org.elasticsearch.hadoop.util.ClusterInfo;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

public class TestMain {

    public static void main(String[] strs){
//        Configuration conf=new Configuration();
//        //conf.set("es.internal.es.version","7");
//        conf.set("es.nodes","10.112.40.14");
//        conf.set("es.port","31508");
//        Settings settings=new HadoopSettings(conf);
//        RestClient restClient=new RestClient(settings);
//        ClusterInfo clusterInfo = restClient.mainInfo();
//        System.out.println(clusterInfo.getMajorVersion());

        Date d=DateUtils.addHours(new Date(),-24);

        System.out.println(d.getTime());

        Long milliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
        System.out.println(milliSecond);

        String spanRange="24";
        int amount = 0 - Integer.valueOf(spanRange);
        Date startTimeM= DateUtils.addHours(new Date(),amount);
        String esQuery = String.format("{\"range\": {\"startTimeMillis\": { \"gte\": \"%s\" }}}", startTimeM.getTime());
        System.out.println(esQuery);
    }

}
